import { createRouter, createWebHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import localCache from '@/utils/cache';
import store from '@/store';
import { tabPaneProps } from 'element-plus';
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/main/main.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    name: '404',
    component: () => import('@/views/404/404.vue')
  }
];
const router = createRouter({
  routes,
  history: createWebHistory()
});
router.beforeEach((to, from) => {
  const token = localCache.getCache('token');
  if (to.path !== '/login') {
    if (!token) {
      return '/login';
    }
    if (to.path === '/main') {
      return '/main/analysis/dashboard';
    }
  }
  // if (to.path === '/login' || to.path === '/') {
  //   if (!token) {
  //     return '/login';
  //   } else {
  //     console.log(from);
  //   }
  // }
});
export default router;
